<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>控制网页中的图片尺寸</title>
</head>
<script>
function downImage(imgD, maxWidth, maxHeight) {
  var image = new Image();
  image.src = imgD.src;
  if (image.width > 0 && image.height > 0) {
	  var rate = (maxWidth / image.width < maxHeight / image.height) 
	  ? maxWidth / image.width : maxHeight / image.height;
	  if (rate <= 1) {
		  imgD.width = image.width * rate;
		  imgD.height = image.height * rate;
	  }
  }
}
</script>

<body>
<img alt="" src="01.jpg" onload=downImage(this,400,267); />

</body>
</html>
